package cn.car.controller;

import cn.car.biz.VehicleCommonInfoBiz;
import cn.car.domains.vo.Result;
import cn.car.domains.vo.vehicleCommon.CreateVehicleCommonReq;
import cn.car.domains.vo.vehicleCommon.UpdateVehicleCommonReq;
import cn.car.domains.vo.vehicleCommon.VehicleCommonInfoRes;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 车辆信息控制器
 */
@RestController
@RequestMapping("/api/vehicleCommon")
@Slf4j
public class VehicleCommonInfoController {

    @Resource
    private VehicleCommonInfoBiz vehicleCommonInfoBiz;

    /**
     * 创建车辆信息
     *
     * @param req 创建车辆请求参数
     */
    @PostMapping("/create")
    public Result<Void> createVehicle(@RequestBody CreateVehicleCommonReq req) {
        vehicleCommonInfoBiz.createVehicle(req);
        return Result.success();
    }


    /**
     * 根据车牌号获取车辆信息
     *
     * @param vehicleNumber 车牌号
     */
    @PostMapping("/getByNumber")
    public Result<VehicleCommonInfoRes> getVehicleByNumber(@RequestParam @NotNull String vehicleNumber) {
        return Result.success(vehicleCommonInfoBiz.getVehicleByNumber(vehicleNumber));
    }

    /**
     * 更新车辆信息
     *
     * @param req 更新车辆请求参数
     */
    @PostMapping("/update")
    public Result<Void> updateVehicle(@RequestBody UpdateVehicleCommonReq req) {
        vehicleCommonInfoBiz.updateVehicle(req);
        return Result.success();
    }

    /**
     * 删除车辆信息
     * @param id 车辆ID
     */
    @PostMapping("/delete")
    public Result<Void> deleteVehicle(@RequestParam @NotNull Long id) {
        vehicleCommonInfoBiz.deleteVehicle(id);
        return Result.success();
    }
}
